import Base from './Base'
import {USER_TYPE, IDENTITY_CARD_TYPE} from '@/lib/const'

class RegUser extends Base {
  constructor ({
    id = '',
    account = '',
    name = '',
    identityType = IDENTITY_CARD_TYPE[0].key,
    identityCard = '',
    mobile = '',
    email = '',
    address = '',
    userType = USER_TYPE[0].key,
    organizationName = '',
    organizationCode = '',
    investmentStyle = '',
    isHoldings = false,
    integral = '0',
    integralRule = '',
    rememberLogin = ''
  }) {
    super({id})

    this.account = account
    this.name = name
    this.identityType = identityType
    this.identityCard = identityCard
    this.mobile = mobile
    this.email = email
    this.address = address
    this.userType = userType
    this.organizationName = organizationName
    this.organizationCode = organizationCode
    this.investmentStyle = investmentStyle
    this.isHoldings = isHoldings
    this.integral = integral
    this.integralRule = integralRule
    this.rememberLogin = rememberLogin
  }
  // 用户登录
  static async login (params) {
    let res = await RegUser.$http.get('/reg/login', {params})
    return res
  }
  // 用户登出
  static async logout () {
    let res = await RegUser.$http.get('/reg/logout')
    return res
  }
  // 获取当前用户信息
  static async getCurrent () {
    let res = await RegUser.$http.get(`${RegUser.$name}/current`)
    return res
  }
  // 证件是否存在
  async checkIdCard () {
    let {identityCard} = this
    let params = {identityCard}
    let res = await RegUser.$http.get(`${RegUser.$name}/identity_card/exist`, {params})
    return res
  }
  // 机构是否存在
  async checkOrg () {
    let {organizationName, organizationCode} = this
    let params = {organizationName, organizationCode}
    let res = await RegUser.$http.get(`${RegUser.$name}/organization/exist`, params)
    return res
  }
}
// 静态属性
RegUser.$name = '/reg/user'
export default RegUser
